<?php
namespace jy_weishop_en;
defined('BY_JYA') or exit('error');
/*
	订单
*/
class order extends \plugin{
	//订单创建时，执行此方法，执行相关操作
	public $sendtypes=array(
		'1'=>'快递配送',
		'2'=>'自提/核销',
		'3'=>'虚拟发货',
	);
	public function create($params,$uid='',$url='',$notpl=false){
		$this->order=$params;
		$this->order['createtime']=TIMESTAMP;
		$uid=$uid?$uid:$_SESSION['uid'];
		$member=pdo_get('jy_weishop_member',array('mid'=>$params['mid']?:$uid),array('level','area_code'));
		if($member['level']){
			$orderstar=pdo_getcolumn('jy_weishop_member_level',array('id'=>$member['level'],'uniacid'=>$_SESSION['uniacid']),'orderstar');
			if(!$params['buytype'] && $orderstar){
				$params['buytype']=1;
			}
		}
		$area_code=$member['area_code'];
		$storeid=$params['storeid'];
		$ordersn=$params['ordersn']?:'SN'.get_ordersn('jy_weishop_order','ordersn');
		if(!$params['merchid'] && $_SESSION['onemerchid']){
			if(!$params['api_data'] || !$params['api_data']['dhmerchid']){
				$params['api_data']['dhmerchid']=$_SESSION['onemerchid'];
			}
		}
		$order=array(
			'uniacid'=>$_SESSION['uniacid'],
			'ordersn'=>$ordersn,
			'mid'=>$params['mid']?:$uid,
			'price'=>$params['price'],
			'ding_price'=>$params['ding_price']?:0,
			'outnum_fee'=>$params['outnum_fee'],
			'goodsprice'=>$params['goodsprice'],
			'dispatchprice'=>$params['dispatchprice'],
			'dispatchid'=>$params['dispatchid'],
			'level_de_price'=>$params['level_de_price'],
			'di_cardfee'=>$params['di_cardfee'],
			'luck_de_price'=>$params['luck_de_price'],
			'buyxiu_de_price'=>$params['buyxiu_de_price'],
			'enough_de_price'=>$params['enough_de_price'],
			'coupon_de_price'=>$params['coupon_de_price'],
			'deductcredit'=>$params['deduct_credit'],
			'delcredit1'=>$params['delcredit1'],
			'deductcredit2'=>$params['deduct_credit2'],
			'couponid'=>$params['couponid'],
			'remark'=>$params['remark'],
			'sendtype'=>$params['sendtype'],
			'is_dingpei'=>$params['is_dingpei'],
			'is_peisong'=>$params['is_peisong']?1:2,
			'addressid'=>$params['addressid'],
			'realname'=>$params['realname'],
			'mobile'=>$params['mobile'],
			'address'=>$params['address']?ijson_encode($params['address']):'',
			'storeid'=>$storeid,
			'merchid'=>$params['merchid']?:$params['goods']['0']['merchid'],
			'plugin_name'=>$params['plugin_name']?:$_SESSION['current_plugin'],
			'tableid'=>intval($params['tableid'])?:$_SESSION['table_id'],
			'area_code'=>$area_code,
			'isdish'=>intval($params['isdish']),
			'diyformdata'=>$params['diyfields'],
			'createtime'=>$params['createtime']?:TIMESTAMP,
			'teamid'=>intval($params['teamid']),
			'is_team'=>intval($params['is_team']),
			'send_status'=>intval($params['send_status']),
			'out_upfee'=>$params['out_upfee'],
			'wxapp_id'=>$_SESSION['appgid']?:0,
			'api_id'=>$params['api_id']?:$params['goods']['0']['api_id'],
			'api_pluginname'=>$params['api_pluginname']?:$params['goods']['0']['api_pluginname'],
			'api_data'=>$params['api_data']?ijson_encode($params['api_data']):'',
			'buytype'=>intval($params['buytype']),
		);
		/*
			核销
		*/
		$num=0;
		$verifynum=0;
		foreach($params['goods'] as &$gv){
			$this->model('goods')->check_buy($gv['goodsid'],$gv['total'],$gv['optionid']);
			$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid']),array('merchid','totalcnf','api_id','api_pluginname'));
			$gv['merchid']=$goodsinfo['merchid'];
			$gv['api_id']=$goodsinfo['api_id'];
			$gv['api_pluginname']=$goodsinfo['api_pluginname'];
			if($goodsinfo['totalcnf']==0){
					//拍下减库存
				if($gv['optionid']){
					pdo_update('jy_weishop_goods_option',array('stock -='=>$gv['total']),array('id'=>$gv['optionid']));
				}else{
					pdo_update('jy_weishop_goods',array('total -='=>intval($gv['total'])),array('id'=>$gv['goodsid']));
					if($storeid){
						pdo_update('jy_weishop_store_goods',array('total -='=>$gv['total']),array('goodsid'=>$gv['goodsid'],'storeid'=>$storeid));
					}
				}
			}
			//判断订单核销分量
			$num +=1;
			if($gv['isverify']==1){
				$verifynum +=1;
			}
		}
		if($verifynum==$num && $verifynum>0){
			$order['isverify']=2;
		}elseif($verifynum<$num && $verifynum>0){
			$order['isverify']=1;
		}else{
			$order['isverify']=0;
		}
		//来源追加订单
		if($params['oldorderid']){
			$uporder=$order;
			unset($uporder['mid'],$uporder['uniacid'],$uporder['ordersn'],$uporder['createtime'],$uporder['storeid']);
			$order_id=$params['oldorderid'];
			pdo_update('jy_weishop_order',$uporder,array('id'=>$order_id));
		}else{
			pdo_insert('jy_weishop_order',$order);
			$order_id=pdo_insertid();
		}
		$this->order['id']=$order_id;
		$this->order['ordersn']=$order['ordersn'];
		//购物卡抵扣
		if($this->order['di_cardfee']>0){
			$this->model('goodscard')->usecard($this->order);
		}
		$member=pdo_get('core_members',array('id'=>$this->order['mid']),array('mobile','nickname','realname'));
		//完善会员信息
		if((!$member['mobile'] && $this->order['mobile']) || (!$member['realname'] && $this->order['realname'])){
			model('core/member')->member_update($order['mid'],array('mobile'=>$member['mobile']?:$this->order['mobile'],'realname'=>$member['realname']?:$this->order['realname']));
		}
		//店内取
		if(!$params['oldorderid'] && ($params['sendtype']==2 || $params['sendtype']==3 || $params['isdish']==1 || $params['make_type']==1 || $params['is_peisong']==1)){
			if($uid){
				$mobile=$member['mobile'];	
				$nickname=$member['nickname'];
			}else{
				$mobile=$params['mobile']?$params['mobile']:'无';
				$nickname=$params['username']?$params['username']:'店面客户';
			}
			$address=pdo_get('core_address',array('id'=>$params['addressid']),array('pcd','address','mobile','name'));
			$address['pcd']=json_decode($address['pcd'],true);
			$addressinfo=$address['pcd']['province'].' '.$address['pcd']['city'].' '.$address['pcd']['district'].' '.$address['pcd']['street'].''.$address['address'];
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$selfcount=pdo_count('jy_weishop_order_self',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime),'id');
			$daysnum=date('Ymd',time());
			$selfnumber='NO'.$daysnum.sprintf("%04d", $selfcount+1);
			$self=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$params['mid']?:$uid,
				'storeid'=>$params['storeid'],
				'orderid'=>$order_id,
				'table_id'=>intval($params['tableid'])?:$_SESSION['table_id'],
				'username'=>$address['name']?:$nickname,
				'mobile'=>$address['mobile']?:$mobile,
				'address'=>$addressinfo,
				'number'=>$selfnumber,
				'status'=>0,
				'type'=>intval($params['self_type']),
				'selftime'=>$params['selftime']?strtotime($params['selftime']):'',
				'out_time'=>trim($params['out_time']),
				'tostoretime'=>trim($params['tostoretime']),
				'merchid'=>$params['merchid']?:$params['goods']['0']['merchid'],
				'createtime'=>time()
			);
			pdo_insert('jy_weishop_order_self',$self);
		}
		//优惠券锁定
		if(!$params['oldorderid'] && $order['couponid']){
			pdo_update('jy_weishop_coupon_getlog',array('islock'=>1),array('id'=>$order['couponid'],'uniacid'=>$_SESSION['uniacid']));
		}
		//整理订单商品
		foreach($params['goods'] as $item){
			$ordergoodsinfo=array();
			if($item['optionid']){
				$ordergoodsinfo['costprice']=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$item['optionid'],'uniacid'=>$_SESSION['uniacid']),'costprice');
			}else{
				$ordergoodsinfo['costprice']=pdo_getcolumn('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']),'costprice');
			}
			$ordergoodsinfo['title']=$item['title'];
			$ordergoodsinfo['image']=$item['image'];
			$new_order_goods=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$params['mid'],
				'orderid'=>$order_id,
				'goodsid'=>$item['goodsid'],
				'optionid'=>$item['optionid'],
				'optiondata'=>$item['optiondata'],
				'goodsnum'=>$item['options']['goodsnum'],
				'istaocan'=>$item['istaocan'],
				'price'=>$item['price'],
				'total'=>$item['total'],
				'merchid'=>$item['merchid'],
				'plugin_name'=>$this->session('fromplugin_name'),
				'frompid'=>$this->session('frompid'),
				'goodsinfo'=>ijson_encode($ordergoodsinfo),
				'api_id'=>$item['api_id'],
				'api_pluginname'=>$item['api_pluginname'],
				'active'=>$item['active']?ijson_encode($item['active']):'',
				'createtime'=>TIMESTAMP,
			);
			//来自直播间
			$room_goods=$this->session('room_goods');
			if($room_goods){
				if($room_goods[$item['goodsid']]){
					$new_order_goods['roomid']=$room_goods[$item['goodsid']];
				}
			}
			$new_order_goods['total_price']=$new_order_goods['price']*$new_order_goods['total'];
			pdo_insert('jy_weishop_order_goods',$new_order_goods);
			//清理购物车
			if($item['cartid']){
				pdo_delete('jy_weishop_member_cart',array('id'=>$item['cartid']));
			}
			//活动插件			
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','active_plugin','active_id'));
			if($goods['active_plugin']){				
				$parameter=array(
					'active_plugin'=>$goods['active_plugin'],
					'active_id'=>$goods['active_id'],
					'goods_id'=>$goods['id'],
					'price'=>$new_order_goods['price'],
					'num'=>$item['total'],
					'optionid'=>$item['optionid'],
					'ordersn'=>$order['ordersn'],
					'order_id'=>$order_id,
					'mid'=>$order['mid'],
					'order_price'=>$order['price'],
				);
				//到指定活动插件下面model/order_create
				$this->model('activity')->order_create($parameter);
			}
			//买家秀清0
			if($item['buyxiu_de_price']>0){
				$this->model('activity')->get_buyxiu_up0($goods['id']);
			}
		}
		//设置单商户费用
		$this->setfee_desc($order_id);
		//发票
		if(!$params['oldorderid'] && $params['invoice'] && $params['invoice']){
			$invoice=array(
				'orderid'=>$order_id,
				'uniacid'=>$_SESSION['uniacid'],
				'type'=>$params['invoice']['type'],
				'goodstype'=>$params['invoice']['goodstype'],
				'name'=>$params['invoice']['name'],
				'code'=>$params['invoice']['code'],
				'email'=>$params['invoice']['email'],
				'bank'=>$params['invoice']['bank'],
				'bankcode'=>$params['invoice']['bankcode'],
			);
			pdo_insert('jy_weishop_order_invoice',$invoice);
		}
		//下单时送积分（非支付，完成时）
		$buy_credit_setting=$this->plugin_setting('buy_credit');		
		if($buy_credit_setting['open'] && $buy_credit_setting['time']=='create'){
			$this->buy_credit($order_id);
		}
		//赠品
		if($params['gift_id']){
			$giftinfo=pdo_get('jy_weishop_goods_gift',array('id'=>$params['gift_id']));
			if($giftinfo['cangetnum']){
				$isget=pdo_count('jy_weishop_order_gift',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'mid'=>$params['mid'],'gift_id'=>$params['gift_id']));
				if($giftinfo['cangetnum']<=$isget){
					$nogift=true;
				}
			}
			if(!$nogift){
				$new_gift=array(
					'uniacid'=>$_SESSION['uniacid'],
					'mid'=>$params['mid'],
					'order_id'=>$order_id,
					'gift_id'=>$params['gift_id'],
					'createtime'=>TIMESTAMP,
					'gifts'=>$giftinfo['gifts'],
				);
				pdo_insert('jy_weishop_order_gift',$new_gift);
			}
		}
		$notice_setting=$this->plugin_setting('notice');
		if($params['plugin_name']=='jy_weidish'){
				$url=custom_url('jy_weidish/orderdetail//id='.$order_id,true);
		}
		if(!$notpl){
			$this->model('notice')->notice_create2buyer($this->order,$url);
			if($notice_setting['seller']){
				foreach($notice_setting['seller'] as $member){
						$this->model('notice')->notice_create2seller($this->order,$member['mid']);
				}
			}
			//打印
			if($params['oldorderid']){
				//追加订单，只打印追加的商品。
				$this->model('printmsg')->storeprint('',$order_id,0,0,'','',$params['goods'],true);
			}else{
				$this->model('printmsg')->storeprint('',$order_id,0,0);
			}
		}
		$this->publish('order.create',$this->order);
		return $order_id;
	}
	public function createaddfee_order($order,$uid='',$url=''){
		$uid=$uid?:$_SESSION['uid'];
		$order=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$order['mid']?:$uid,
			'price'=>$order['addprice'],
			'orderid'=>intval($order['id']),
			'createtime'=>$order['createtime']?:TIMESTAMP,
		);
		pdo_insert('jy_weishop_order_addfee',$order);
		$order_id=pdo_insertid();
		return $order_id;
	}
	public function get_order($order_id,$merchid=0){
		if($this->order && $this->order['id']==$order_id){
			return $this->order;
		}
		$this->order=pdo_get('jy_weishop_order',array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		if($merchid){
			$this->order['goods']=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order_id,'merchid'=>$merchid));
		}else{
			$this->order['goods']=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order_id));
		}
		$this->order['total_price']=$this->order['goodsprice'];
		foreach($this->order['goods'] as &$goods){
			$goods_data=pdo_get('jy_weishop_goods',array('id'=>$goods['goodsid']),array('title','image','type','fang_credit2','no_de_sales','isdiyprice','diyprice','isverify','goodssn','productsn','noticemid','totalcnf','noticetype'));
            $goods_data['image']=tomedia($goods_data['image']);
			//商品规格
			if($goods['optionid']){
				$options=pdo_get('jy_weishop_goods_option',array('id'=>$goods['optionid']),array('title','specs'));
				$specs=$options['specs'];
				if($goods['istaocan']){
					$goods['selespename']=$options['title'];
				}else{
					$specs=explode("_",$specs);
					foreach($specs as &$spec){
						$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
					}
					$goods['selespename']=implode("，",$specs);
				}
			}
			$goods=array_merge($goods,$goods_data);
		}
		$this->order['express']=pdo_get('jy_weishop_order_express',array('orderid'=>$order_id));
		return $this->order;
	}
	
	//订单取消
	public function order_cancel($order_id,$istask=false){
		$this->get_order($order_id);
		if($this->order['status']==1 && $this->order['ispay']){
			$this->model('order/refund')->order_cancelfee($this->order);
		}
		pdo_update('jy_weishop_order',array('status'=>4),array('id'=>$order_id));
		pdo_update('jy_weishop_order_goods',array('status'=>4),array('orderid'=>$order_id));
		//恢复库存
		$getgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order_id),array('goodsid','total','optionid','storeid'));
		foreach($getgoods as $item){
			if($item['optionid']){
				pdo_update('jy_weishop_goods_option',array('stock +='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['optionid']));
			}else{
				pdo_update('jy_weishop_goods',array('total +='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
				if($item['storeid']){
					pdo_update('jy_weishop_store_goods',array('total +='=>$item['total']),array('goodsid'=>$item['goodsid'],'storeid'=>$item['storeid']));
				}
			}
		}
		//优惠券解锁
		if($this->order['couponid']){
			pdo_update('jy_weishop_coupon_getlog',array('islock'=>0),array('id'=>$this->order['couponid'],'uniacid'=>$_SESSION['uniacid']));
		}
		//退购物卡费
		if($this->order['di_cardfee']>0){
			$this->model('goodscard')->tuiorder($this->order);
		}
		$notice_setting=$this->plugin_setting('notice');
		$this->model('notice')->notice_cancel2buyer($this->order);
		if($notice_setting['seller']){
			foreach($notice_setting['seller'] as $member){
				$this->model('notice')->notice_cancel2seller($this->order,$member['mid']);
			}
		}
	}
	//订单删除
	public function order_delete($order_id,$userdeleted=false){
		$this->get_order($order_id);
		if(!$this->order){
			exi('订单不存在或者不支持删除！','error');
		}
		if($userdeleted){
			pdo_update('jy_weishop_order',array('userdeleted'=>1),array('id'=>$order_id));
		}else{
			pdo_update('jy_weishop_order',array('deleted'=>1),array('id'=>$order_id));
		}
		if(!$this->order['status']){
			//恢复库存
			$getgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order_id),array('goodsid','total','optionid','storeid'));
			foreach($getgoods as $item){
				if($item['optionid']){
					pdo_update('jy_weishop_goods_option',array('stock +='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['optionid']));
				}else{
					pdo_update('jy_weishop_goods',array('total +='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
					if($item['storeid']){
						pdo_update('jy_weishop_store_goods',array('total +='=>$item['total']),array('goodsid'=>$item['goodsid'],'storeid'=>$item['storeid']));
					}
				}
			}
		}
	}
	public function order_rdelete($order_id){
		$this->get_order($order_id);
		if(!$this->order || ($this->order['status']!=-1 && $this->order['status']!=4)){
			exi('订单不存在或者不支持删除！','error');
		}
		pdo_delete('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order_id));
		if(!$this->order['status']){
			//恢复库存
			$getgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order_id),array('goodsid','total','optionid','storeid'));
			foreach($getgoods as $item){
				if($item['optionid']){
					pdo_update('jy_weishop_goods_option',array('stock +='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['optionid']));
				}else{
					pdo_update('jy_weishop_goods',array('total +='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
					if($item['storeid']){
						pdo_update('jy_weishop_store_goods',array('total +='=>$item['total']),array('goodsid'=>$item['goodsid'],'storeid'=>$item['storeid']));
					}
				}
			}
		}
	}
	//订单恢复
	public function order_reset($order_id,$userdeleted=false){
		$this->get_order($order_id);
		if(!$this->order){
			exi('订单不存在！','error');
		}
		if($userdeleted){
			pdo_update('jy_weishop_order',array('userdeleted'=>0),array('id'=>$order_id));
		}else{
			pdo_update('jy_weishop_order',array('deleted'=>0),array('id'=>$order_id));
		}
		if(!$this->order['status']){
			//恢复库存
			$getgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order_id),array('goodsid','total','optionid','storeid'));
			foreach($getgoods as $item){
				if($item['optionid']){
					$this->model('goods')->check_buy($item['goodsid'],$item['total'],$item['optionid']);
					pdo_update('jy_weishop_goods_option',array('stock -='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['optionid']));
				}else{
					$this->model('goods')->check_buy($item['goodsid'],$item['total']);
					pdo_update('jy_weishop_goods',array('total -='=>$item['total']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
					if($item['storeid']){
						pdo_update('jy_weishop_store_goods',array('total -='=>$item['total']),array('goodsid'=>$item['goodsid'],'storeid'=>$item['storeid']));
					}
				}
			}
		}
	}
	public function order_cancelfh($order_id){
		pdo_update('jy_weishop_order',array('status'=>1),array('id'=>$order_id));
		pdo_update('jy_weishop_order_goods',array('status'=>1),array('orderid'=>$order_id));
	}
	//支付
	public function order_pay($order_id,$params,$url='',$notpl=false){
		$this->get_order($order_id);
		if(!$this->order || $this->order['ispay']){
			exi('订单不存在或者已支付！','error');
		}
		$update=array(
				'status'=>$params['status']?:1,
				'paytype'=>$params['paytype'],
				'transid'=>$params['transid'],
		);
		if($params['paytype']=='hdfk'){
			$update['ispay']=0;
		}else{
			$update['ispay']=1;
			$update['paytime']=TIMESTAMP;
		}
		foreach($update as $key=>$value){
			$this->order[$key]=$value;
		}
		pdo_update('jy_weishop_order',$update,array('id'=>$order_id));
		$this->order['paytype']=$params['paytype'];
		$this->order['transid']=$params['transid'];
		//更新单商品支付状态
		if($params['clearstatus']){
			$clearstatus=1;
		}
		pdo_update('jy_weishop_order_goods',array('status'=>1,'ispay'=>$update['ispay'],'storeid'=>$this->order['storeid'],'clearstatus'=>$clearstatus),array('orderid'=>$order_id));
		$noticemids=array();
		foreach($this->order['goods'] as $item){
			if($item['totalcnf']==1){
				//付款减库存
				if($item['optionid']){
					pdo_update('jy_weishop_goods_option',array('stock -='=>$item['total']),array('id'=>$item['optionid']));
				}else{
					pdo_update('jy_weishop_goods',array('total -='=>$item['total']),array('id'=>$item['goodsid']));
					if($this->order['storeid']){
						pdo_update('jy_weishop_store_goods',array('total -='=>$item['total']),array('goodsid'=>$item['goodsid'],'storeid'=>$this->order['storeid']));
					}
				}
			}
			pdo_update('jy_weishop_goods',array('salerealnum +='=>1,'salenum +='=>$item['total']),array('id'=>$item['goodsid']));			
			//直播数据更新
			if($item['roomid']){
				pdo_update('core_account_wxapp_live_rooms',array('totalfee +='=>$item['total_price'],'salenum +='=>$item['total']),array('id'=>$item['roomid'],'uniacid'=>$_SESSION['uniacid']));
			}
			//推送消息给卖家		
			if($item['noticemid']){
				if(strpos($item['noticetype'],';1;') !== false){
					if(!in_array($item['noticemid'],$noticemids)){
						$noticemids[]=$item['noticemid'];
					}
				}
			}
			//活动数据
			if($item['active']){
				$active=json_decode($item['active'],true);
				if($active['libao_id']){
					pdo_update('jy_weishop_sale_libao',array('status'=>1),array('id'=>$active['libao_id']));
				}
			}
		}
		if($this->order['merchid']){
			$ismerch = $this->plugin_exists('jy_merch');
		}
		if(!$notpl){
			foreach($noticemids as $n){
				$this->model('notice')->notice_pay2seller($this->order,$n,$url);
			}
			if($ismerch){
				$merch=pdo_get('jy_merch_user',array('id'=>$this->order['merchid']));
				if($merch['mid']){
						$this->order['merchname']=$merch['merchname'];
						$url='jy_merch/manage.order_list/';
						$this->model('notice')->notice_pay2seller($this->order,$merch['mid'],$url);
				}
			}
		}
		/*
			按商品虚拟商品和核销商品自动发货
			非拼团订单，才自动发货
		*/
		if($this->order['is_team']!=1 && $this->order['isdish']!=1){
			foreach($this->order['goods'] as $vv){
				//已经整理出了商品类型type,isverify，只要支持核销，无论什么商品都可以核销！
				if($vv['isverify']==1 && $vv['type']!=2){
					if($vv['type']==3){
						$this->order_send_verifygoods($order_id,$vv['goodsid'],$this->order['sendtype']);
					}elseif($vv['type']==0){
						//实体物品，需配送时，依然生成核销码，但是不刷新配送状态
						$this->order_send_verify($order_id,$vv['goodsid'],$this->order['sendtype']);
					}else{
						$this->order_send_verify($order_id,$vv['goodsid'],$this->order['sendtype']);
					}
				}elseif($vv['type']==1 || $vv['type']==2){
					//虚拟发货，如果是自动发货
					$goods=pdo_get('jy_weishop_goods',array('id'=>$vv['goodsid']),array('type','virtualsend','virtualsendcont','virtual_template_id'));
					if(($goods['virtualsend']) || $vv['type']==2){
						$vv=array_merge($vv,$goods);
						$this->order_send_virtual($order_id,$vv);
					}
				}
			}
		}
		//会员等级变更
		$this->model('member')->check_uplevel($this->order['mid'],1);
		//优惠券已使用
		if($this->order['couponid']){
			$this->model('coupon')->usecoupon($this->order['couponid'],$this->order['ordersn']);
		}
		//购物送积分
		$buy_credit_setting=$this->plugin_setting('buy_credit');
		if($buy_credit_setting['open'] && $buy_credit_setting['time']=='pay'){
			$this->order['buy_credit']=$this->buy_credit($order_id,$ismerch);
		}
		$buy_credit3_setting=$this->plugin_setting('buy_credit3');
		if(($buy_credit3_setting['open'] || $ismerch) && $buy_credit3_setting['time']=='pay'){
			$this->order['buy_credit3']=$this->buy_credit3($order_id,$ismerch);
		}
		//返现
		$this->fang_credit2($order_id);
		$this->fang_credit($order_id);
		//抵扣积分
		if($this->order['deductcredit']){
			$this->deduct_credit($order_id);
		}
		//购物送券，这里判断是否需要购物送券。如有需要，推送相关消息
		foreach($this->order['goods'] as $item){
			$coupons=pdo_getall('jy_weishop_coupon_goodsendtask',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'goodsid'=>$item['goodsid']));
			foreach($coupons as $coupon){
				if($coupon && $coupon['couponid'] && $coupon['sendpoint']==2 && $coupon['num'] >= $coupon['sendnum']){
					//购物送券活动存在，且发送时机为订单付款时，且剩余数量高于每个用户发送数量，此时尝试推送优惠券消息。
					$params=array(
						'mid'=>$this->order['mid'],
						'ac_type'=>'goods',
						'ac_id'=>$coupon['id'],
						'remark'=>'购物送券活动',
					);
					$this->model('coupon')->give_coupon($params);
				}
			}
		}
		//满额送券，查找是否有符合条件的满额送券活动
		$parameter=array(
			'params'=>array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'price <='=>$this->order['price']),
			'orderby'=>'price desc',
			'limit'=>'1',
		);
		$coupons=pdo_getlist('jy_weishop_coupon_sendtasks',$parameter);
		$coupon=$coupons[0];
		if($coupon['couponid'] && $coupon['sendpoint']==2 && $coupon['num'] >= $coupon['sendnum']){
				$params=array(
					'mid'=>$this->order['mid'],
					'ac_type'=>'order',
					'ac_id'=>$coupon['id'],
					'remark'=>'订单满额送券活动',
				);
				$this->model('coupon')->give_coupon($params);
		}
		//游戏营销，购物参与
		foreach($this->order['goods'] as $item){
			$gamepost=array(
				'goodsid'=>$item['goodsid'],
				'type'=>2,
			);
			$this->model('game')->up_addgame($gamepost,$this->order['mid']);
		}
		$gamepost=array(
				'type'=>1,
				'price'=>$this->order['price'],
		);
		$this->model('game')->up_addgame($gamepost,$this->order['mid']);
		//自动派单，非拼团，非制作商品
		if(($this->order['sendtype']==1 || $this->order['sendtype']==4) && $this->order['is_team']!=1 && $this->order['send_status']!=11){			
			if($this->plugin_exists('jy_peisong')){
				$citypeisong=$this->plugin_setting('citypeisong');
				if($citypeisong['isopen']==1 && $citypeisong['set_peisonguser']==1){
					model('jy_peisong/order')->order_pai($this->order);
				}
			}
		}
		//礼品订单更新
		pdo_update('jy_weishop_order_gift',array('status'=>1),array('status'=>0,'uniacid'=>$_SESSION['uniacid'],'order_id'=>$this->order['id']));
		if(!$notpl){
			//打印
			$this->model('printmsg')->storeprint('',$order_id,0,0);
			//模板消息推送
			$notice_setting=$this->plugin_setting('notice');
			if(!$_SESSION['wxapp_id']){
				$this->model('notice')->notice_pay2buyer($this->order,$url);
			}
			if($notice_setting['seller']){
				foreach($notice_setting['seller'] as $member){
					$this->model('notice')->notice_pay2seller($this->order,$member['mid'],$url);
				}
			}
			//推送消息给店员
			if($this->order['store_id']){
				$sellers=pdo_getall('jy_weishop_store_worker',array('storeid'=>$this->order['store_id'],'status'=>1,'getmessage'=>1),'mid');
			}
			if($sellers){
				foreach($sellers as $v){
					$this->model('notice')->notice_pay2seller($this->order,$v['mid'],$url);
				}
			}
		}
		$event=array(
			'type'=>'pay',
			'order'=>$this->order,
		);
		$this->model('store')->up_commission($this->order);
		if($this->order['merchid'] && $this->plugin_exists('jy_merch')){
			model('jy_merch/model')->up_pay($this->order);
		}
		$this->publish('order.change',$event);
		if($this->order['paytype']=='alipay'){
			//ISV 返佣激励
			model('jy_alipay/alipay')->back_order($this->order);
		}
	}
	//多退少补支付
	public function order_addfeepay($order_id,$params,$url=''){
		$order=pdo_get('jy_weishop_order_addfee',array('id'=>$order_id));
		if(!$order || $order['ispay']){
			exi('订单不存在或者已支付！','error');
		}
		$update=array(
				'status'=>$params['status']?:1,
				'paytype'=>$params['paytype'],
				'transid'=>$params['transid'],
		);
		if($params['paytype']=='hdfk'){
			$update['ispay']=0;
		}else{
			$update['ispay']=1;
			$update['paytime']=TIMESTAMP;
		}
		foreach($update as $key=>$value){
			$this->order[$key]=$value;
		}
		pdo_update('jy_weishop_order',array('ispayadd'=>1),array('id'=>$order['orderid']));
		pdo_update('jy_weishop_order_addfee',$update,array('id'=>$order_id));
	}
	//发货
	public function order_send($order_id,$params=array(),$isup=false){
		$this->get_order($order_id);
		if($this->order['status']==2 || ($this->order['send_status']==$params['send_status'] && $params['send_status'])){
			if(!$isup){
				exi('不能发货，该订单已发货！','error');
			}
		}		
		if($params['morefa']){
			foreach($params['goods'] as $pgv){
				$ordergoodsid=';';
				if($pgv['canfa']){
					$ordergoodsid .=$pgv['id'].';';
					if($pgv['fatype'] && !$pgv['content']){
						exi($pgv['title'].'-商品，发货内容不能为空！','error');
					}else if(!$pgv['fatype'] && !$pgv['express'] && !$pgv['expresssn']){
						exi($pgv['title'].'-商品，快递公司,快递单号不能为空！','error');
					}
					$pgv['ordergoodsid']=$ordergoodsid;
					$this->order_sendone($order_id,$pgv);
				}
			}
		}else{
			$ordergoodsid=';';
			foreach($params['goods'] as $pgv){
				if($pgv['canfa']){
					$ordergoodsid .=$pgv['id'].';';
				}
			}
			$params['ordergoodsid']=$ordergoodsid;
			$this->order_sendone($order_id,$params);
		}
		return true;
	}
	//发货
	public function order_sendone($order_id,$params=array()){
		if($params['express'] || $params['expresssn'] || $params['opensend_type'] || $params['content']){
			$isfaid=pdo_getcolumn('jy_weishop_order_express',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order_id,'ordergoodsid'=>$params['ordergoodsid']),'id');
			$data=array(
				'express_id'=>intval($params['express']),
				'expresssn'=>$params['expresssn'],
				'opensend_type'=>$params['opensend_type'],
				'fatype'=>$params['fatype'],
				'content'=>$params['content'],
			);
			if($isfaid){
				pdo_update('jy_weishop_order_express',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$isfaid));
				return true;
			}else{
				$data['uniacid']=$_SESSION['uniacid'];
				$data['orderid']=$order_id;
				$data['ordergoodsid']=$params['ordergoodsid'];
				$data['morefa']=$params['morefa'];
				$data['createtime']=TIMESTAMP;
				pdo_insert('jy_weishop_order_express',$data);
			}
		}
		if($params['send_status']){
			pdo_update('jy_weishop_order',array('send_status'=>$params['send_status'],'paisong_type'=>$params['paisong_type']),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		}else{
			$ordergoodsid=str_array($params['ordergoodsid']);
			if($ordergoodsid){
				pdo_update('jy_weishop_order_goods',array('status'=>2,'sendtime'=>time()),array('orderid'=>$order_id,'id'=>$ordergoodsid,'uniacid'=>$_SESSION['uniacid']));
			}else{
				pdo_update('jy_weishop_order_goods',array('status'=>2,'sendtime'=>time()),array('orderid'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
			}
			$newstatus=2;
			$lastnum=pdo_count('jy_weishop_order_goods',array('status'=>1,'orderid'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
			if($lastnum){
				$newstatus=21;
			}
			pdo_update('jy_weishop_order',array('status'=>$newstatus,'sendtime'=>time()),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
			$this->order['sendtime']=TIMESTAMP;
			$this->order['express']=$data;
			$notice_setting=$this->plugin_setting('notice');
			if($this->order['peisong_id']){
				$this->model('notice')->notice_pei2buyer($this->order);
			}else{
				$this->model('notice')->notice_send2buyer($this->order);
			}
			if($notice_setting['seller']){
				foreach($notice_setting['seller'] as $member){
					$this->model('notice')->notice_send2seller($this->order,$member['mid']);
				}
			}
			if($this->order['merchid']){
				$ismerch = $this->plugin_exists('jy_merch');
				if($ismerch){
					$merch=pdo_get('jy_merch_user',array('id'=>$this->order['merchid']));
					if($merch['mid']){
						$url=custom_url('jy_merch/manage.order_list//',true);
						$this->model('notice')->notice_send2seller($this->order,$merch['mid'],$url);
					}
				}
			}
		}
		return true;
	}
	//自动发货
	public function order_vsend($order_id,$params=array()){
		pdo_update('jy_weishop_order',array('status'=>2,'sendtime'=>TIMESTAMP,'finishtime'=>TIMESTAMP),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		pdo_update('jy_weishop_order_goods',array('status'=>2,'sendtime'=>TIMESTAMP,'finishtime'=>TIMESTAMP),array('orderid'=>$order_id));
		$this->get_order($order_id);
		$this->order['sendtime']=TIMESTAMP;
		$this->order['finishtime']=TIMESTAMP;
		$this->order['mobile']=pdo_getcolumn('core_members',array('id'=>$this->order['mid']),'mobile');	
		$this->order['nickname']=$nickname=pdo_getcolumn('core_members',array('id'=>$this->order['mid']),'nickname');
		$this->order_receive($order_id,true);
		$notice_setting=$this->plugin_setting('notice');
		$this->model('notice')->notice_vsend2buyer($this->order);
		if($notice_setting['seller']){
			foreach($notice_setting['seller'] as $member){
				$this->model('notice')->notice_send2seller($this->order,$member['mid']);
			}
		}
		if($this->order['merchid']){
				$ismerch = $this->plugin_exists('jy_merch');
				if($ismerch){
					$merch=pdo_get('jy_merch_user',array('id'=>$this->order['merchid']));
					if($merch['mid']){
						$url=custom_url('jy_merch/manage.order_list//',true);
						$this->model('notice')->notice_send2seller($this->order,$merch['mid'],$url);
					}
				}
		}
		
	}
	public function order_send_virtual($order_id,$goods=false){
		$this->get_order($order_id);
		if(is_string($goods)){
			//兼容直接自定义发货内容的类型
			$content=$goods;
			$goods=false;
		}
		if(!$goods){
			$goodsid=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$orderid),'goodsid');
			$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid),array('id','type','virtualsend','virtualsendcont','virtual_template_id'));
			if($content){
				$goods['virtualsendcont']=$content;
			}
		}
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'orderid'=>$order_id,
			'goodsid'=>$goods['goodsid'],
			'createtime'=>TIMESTAMP,
		);
		$virtualinfo='';
		for($i=0;$i<$goods['total'];$i++){
				$num=$i+1;
				$data['content']='';
				if($goods['type']==1){
					//发需虚拟物品
					for($i=0;$i<$goods['total'];$i++){
						$num=$i+1;
						$data['content'] .='发货信息('.$num.'):'.$goods['virtualsendcont'];
					}
				}else{
				//发卡密
					$virtual_data=pdo_get('jy_weishop_virtual_data',array('tempid'=>$goods['virtual_template_id'],'mid'=>0),array('id','fields'));
					$virtual_update=array(
						'mid'=>$this->order['mid'],
						'usetime'=>TIMESTAMP,
						'orderid'=>$this->order['id'],
						'ordersn'=>$this->order['ordersn'],
						'price'=>$this->order['price'],
					);
					pdo_update('jy_weishop_virtual_data',$virtual_update,array('id'=>$virtual_data['id']));
					//更新卡密库存
					$this->model('order')->up_virtualtotal($goods['virtual_template_id']);
					$virtual_temp=pdo_get('jy_weishop_virtual_temp',array('id'=>$goods['virtual_template_id']));
					if($virtual_data && $virtual_temp){
						$virtual_data['fields']=json_decode($virtual_data['fields'],true);
						$virtual_temp['fields']=json_decode($virtual_temp['fields'],true);
						foreach($virtual_temp['fields'] as $field){
							$data['content'].=$field['title'].'('.$num.')：'.$virtual_data['fields'][$field['kw']].' ';
						}
					}
					$data['virtualid']=$goods['virtual_template_id'];
				}
				$virtualinfo.=$data['content'];
				pdo_insert('jy_weishop_order_virtual',$data);
		}
		$this->order['virtualinfo']=$virtualinfo;
		pdo_update('jy_weishop_order',array('virtualsendinfo'=>$virtualinfo),array('id'=>$this->order['id']));
		//更新订单状态，发货
		$this->order_vsend($order_id);
		return true;
	}
	public function order_send_verify($order_id,$goodsid='',$sendtype=0){
		//自提核销
		$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid),array('merchid','verifytype','usetime'));
		$goods['total']=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$order_id,'goodsid'=>$goodsid),'total');
		$order_verify=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$this->order['mid'],
			'orderid'=>$order_id,
			'merchid'=>$goods['merchid'],
			'goodsid'=>$goodsid,
			'createtime'=>TIMESTAMP,
			'status'=>0,
			'store_id'=>$this->order['storeid'],
		);
		if($goods['usetime']){
			$order_verify['endtime']=TIMESTAMP+$goods['usetime']*86400;
		}
			if($goods['verifytype']==0){
				//按订单核销
				do{
					$verify_code=random(10);
				}while(pdo_getcolumn('jy_weishop_order_verify',array('verify_code'=>$verify_code),'id'));
				$data=array(
					'verifytype'=>0,
					'verify_code'=>$verify_code,
				);
				$order_verify=array_merge($data,$order_verify);
				
				pdo_insert('jy_weishop_order_verify',$order_verify);
			}elseif($goods['verifytype']==1){
				//按次核销
				do{
					$verify_code=random(10);
				}while(pdo_getcolumn('jy_weishop_order_verify',array('verify_code'=>$verify_code),'id'));
				$data=array(
					'verifytype'=>1,
					'verify_num'=>$goods['total'],
					'verify_code'=>$verify_code,
				);
				$order_verify=array_merge($data,$order_verify);
				pdo_insert('jy_weishop_order_verify',$order_verify);
			}elseif($goods['verifytype']==2){
				//按消费码核销				
				for($i=0;$i<$goods['total'];$i++){
					do{
						$verify_code=random(10);
					}while(pdo_getcolumn('jy_weishop_order_verify',array('verify_code'=>$verify_code),'id'));
					$data=array(
						'verifytype'=>2,
						'verify_code'=>$verify_code,
					);
					$order_verify=array_merge($data,$order_verify);
					pdo_insert('jy_weishop_order_verify',$order_verify);
				}
				
			}
		if($sendtype!=1 && $sendtype!=4){
			pdo_update('jy_weishop_order',array('status'=>2),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
			pdo_update('jy_weishop_order_goods',array('status'=>2),array('orderid'=>$order_id));
		}
		return true;
	}
	public function order_verify($verify_code,$clerk_id){
		$order_verify=pdo_get('jy_weishop_order_verify',array('verify_code'=>$verify_code));
		if(!$order_verify){
			exi('核销码不存在！','error');
		}
		if($order_verify['status'] ){
			exi('核销码已被使用或已过期！','error');
		}
		if($order_verify['endtime'] && $order_verify['endtime']<TIMESTAMP){
			pdo_update('jy_weishop_order_verify',array('status'=>2),array('orderid'=>$order_verify['orderid']));
			exi('该核销码已过期！','error');
		}
		if($order_verify['verifytype']==0){
			//按订单核销
			$update=array(
				'status'=>1,
				'clerk_id'=>$clerk_id,
				'verifytime'=>TIMESTAMP,
			);
			pdo_update('jy_weishop_order_verify',$update,array('id'=>$order_verify['id']));
			$check_receive=$this->model('verify')->check_receive($order_verify['orderid']);
			if($check_receive){
				$this->order_receive($order_verify['orderid']);
			}
		}elseif($order_verify['verifytype']==1){
			//按次核销
			$verifydata=$order_verify['verifydata']?json_decode($order_verify['verifydata'],true):array();
			$verifydata[]=array(
				'clerk_id'=>$clerk_id,
				'verifytime'=>TIMESTAMP,
			);
			$update=array(
				'verifydata'=>ijson_encode($verifydata),
				'verify_num -='=>1,
			);
			if($order_verify['verify_num']==1){
				$update['status']=1;
			}
			pdo_update('jy_weishop_order_verify',$update,array('id'=>$order_verify['id']));
			if($update['status']==1){
				$check_receive=$this->model('verify')->check_receive($order_verify['orderid']);
				if($check_receive){
					$this->order_receive($order_verify['orderid']);
				}
			}
		}elseif($order_verify['verifytype']==2){
			//按消费码核销
			$update=array(
				'status'=>1,
				'clerk_id'=>$clerk_id,
				'verifytime'=>TIMESTAMP,
			);
			pdo_update('jy_weishop_order_verify',$update,array('id'=>$order_verify['id']));
			$check_receive=$this->model('verify')->check_receive($order_verify['orderid']);
			if($check_receive){
				$this->order_receive($order_verify['orderid']);
			}
		}
		$order_verify['salerid']=$clerk_id;
		$event=array(
			'type'=>'order',
			'order'=>$order_verify,
		);
		$this->publish('order.verify',$event);
	}
	public function order_send_verifygoods($order_id,$goodsid='',$sendtype=0){
		//计次核销
		$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid),array('verifygoodsnum','verifygoodsdays','verifygoodslimittype','verifygoodslimitdate'));
		$goods['total']=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$order_id,'goodsid'=>$goodsid),'total');
		$goods['total']=$goods['total']?:1;
		$verifygoods=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'orderid'=>$order_id,
			'ordergoodsid'=>$goodsid,
			'limitdays'=>$goods['verifygoodsdays'],
			'limitnum'=>$goods['verifygoodsnum']*$goods['total'],
			'limittype'=>$goods['verifygoodslimittype'],
			'limitdate'=>$goods['verifygoodslimitdate'],
			'starttime'=>TIMESTAMP,
			'used'=>0,
			'storeid'=>$this->order['storeid'],
			'merchid'=>$this->order['merchid'],
			'verifycode'=>random(10),
		);
		pdo_insert('jy_weishop_verifygoods',$verifygoods);
		if($sendtype!=1 && $sendtype!=4){
			pdo_update('jy_weishop_order',array('status'=>2),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
			pdo_update('jy_weishop_order_goods',array('status'=>2),array('orderid'=>$order_id));
		}
		return true;
	}
	public function order_verifygoods($verify_code,$clerk_id,$num=1,$remarks='',$noapi=false){
		$goods_verify=pdo_get('jy_weishop_verifygoods',array('verifycode'=>$verify_code));
		if(!$goods_verify){
			exi('核销码不存在！','error');
		}
		if (!(empty($goods_verify['limitnum']))){
			$verifygoodlogs = pdo_getall('jy_weishop_verifygoods_log',array('verifygoodsid'=>$goods_verify['id']));
			$verifynum = 0;
			foreach ($verifygoodlogs as $verifygoodlog ) 
			{
				$verifynum += intval($verifygoodlog['verifynum']);
			}
			$lastverifys = intval($goods_verify['limitnum']) - $verifynum;
			if ($lastverifys < 1) 
			{
				exi('核销次数已用完!', 'error');
			}
		}
		if (empty($goods_verify['limittype'])) {
			$goods_verify['limitdays']=$goods_verify['limitdays']?:365;
			$limitdate = intval($goods_verify['starttime']) + (intval($goods_verify['limitdays']) * 86400);
		}else{
			$limitdate = intval($goods_verify['limitdate']);
		}
		if ($limitdate < time()) {
			exi('该商品已过期!', 'error');
		}
		$jy_offlineapi = $this->plugin_exists('jy_offlineapi');
		if($jy_offlineapi && !$noapi){
			$goods_verify['verifynum']=$num;
			$goods_verify['salerid']=$clerk_id;
			$isapi=model('jy_offlineapi/model')->send_api($goods_verify);
			if($isapi){
				return true;
			}
		}
		$log=array(
			'uniacid'=>$_SESSION['uniacid'],
			'verifygoodsid'=>$goods_verify['id'],
			'salerid'=>$clerk_id,
			'storeid'=>$goods_verify['storeid'],
			'merchid'=>$goods_verify['merchid'],
			'verifynum'=>$num,
			'remarks'=>$remarks,
			'verifydate'=>time(),
		);
		pdo_insert('jy_weishop_verifygoods_log',$log);
		$logs=pdo_getsum('jy_weishop_verifygoods_log',array('verifygoodsid'=>$goods_verify['id']),'verifynum');
		if($logs==$goods_verify['limitnum'] && $goods_verify['limitnum']>0){
			pdo_update('jy_weishop_verifygoods',array('used'=>1,'codeinvalidtime'=>time()),array('id'=>$goods_verify['id']));
			$check_receive=$this->model('verify')->check_receive($goods_verify['orderid']);
			if($check_receive){
				$this->order_receive($goods_verify['orderid']);
			}
		}
	}
	//确认收货，完成订单
	public function order_receive($order_id,$ismsg=false){
		$this->get_order($order_id);
		if($this->order['status']==3 && $this->order['finishtime']){
			return false;
		}
		$update=array('status'=>3,'finishtime'=>TIMESTAMP);
		pdo_update('jy_weishop_order',$update,array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		pdo_update('jy_weishop_order_goods',$update,array('orderid'=>$order_id));
		$notice_setting=$this->plugin_setting('notice');
		if(!$ismsg){
			$this->model('notice')->notice_receive2buyer($this->order);
			if($notice_setting['seller']){
				foreach($notice_setting['seller'] as $member){
					$this->model('notice')->notice_receive2seller($this->order,$member['mid']);
				}
			}
		}
		if($this->order['merchid']){
			$ismerch = $this->plugin_exists('jy_merch');
		}
		//购物送积分
		$buy_credit_setting=$this->plugin_setting('buy_credit');
		if($buy_credit_setting['open'] && $buy_credit_setting['time']=='complete'){
			$this->buy_credit($order_id,$ismerch);
		}
		$buy_credit3_setting=$this->plugin_setting('buy_credit3');
		if(($buy_credit3_setting['open'] || $ismerch) && $buy_credit3_setting['time']=='complete'){
			$this->buy_credit3($order_id,$ismerch);
		}
		//会员等级变更
		$this->model('member')->check_uplevel($this->order['mid'],1);
		//购物送券，这里判断是否需要购物送券。如有需要，推送相关消息
		$noticemids=array();
		foreach($this->order['goods'] as $item){
			$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid']),array('noticemid','totalcnf','noticetype'));
			$coupon=pdo_get('jy_weishop_coupon_goodsendtask',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'goodsid'=>$item['goodsid']));
			if($coupon && $coupon['couponid'] && $coupon['sendpoint']==1 && $coupon['num'] >= $coupon['sendnum']){
				//购物送券活动存在，且发送时机为订单付款时，且剩余数量高于每个用户发送数量，此时尝试推送优惠券消息。
				$params=array(
					'mid'=>$this->order['mid'],
					'ac_type'=>'goods',
					'ac_id'=>$coupon['id'],
					'remark'=>'购物送券活动',
				);
				$this->model('coupon')->give_coupon($params,true);
			}
			//更新单商品支付状态
			pdo_update('jy_weishop_order_goods',array('status'=>3),array('id'=>$item['id']));
			//推送消息给卖家		
			if($goodsinfo['noticemid']){
				if(strpos($goodsinfo['noticetype'],';2;') !== false){
					if(!in_array($goodsinfo['noticemid'],$noticemids)){
						$noticemids[]=$goodsinfo['noticemid'];
					}
				}
			}
		}
		if($noticemids){
			foreach($noticemids as $n){
				$this->model('notice')->notice_receive2seller($this->order,$n);	
			}
		}
		if($this->order['merchid']){
				$ismerch = $this->plugin_exists('jy_merch');
				if($ismerch){
					$merch=pdo_get('jy_merch_user',array('id'=>$this->order['merchid']));
					if($merch['mid']){
						$url=custom_url('jy_merch/manage.order_list//',true);
						$this->model('notice')->notice_receive2seller($this->order,$merch['mid'],$url);
					}
				}
		}
		//满额送券，查找是否有符合条件的满额送券活动
		$parameter=array(
			'params'=>array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'price <='=>$this->order['price']),
			'orderby'=>'price desc',
			'limit'=>'1',
		);
		$coupons=pdo_getlist('jy_weishop_coupon_sendtasks',$parameter);
		$coupon=$coupons[0];
		if($coupon && $coupon['couponid'] && $coupon['sendpoint']==1 && $coupon['num'] >= $coupon['sendnum']){
			$params=array(
					'mid'=>$this->order['mid'],
					'ac_type'=>'order',
					'ac_id'=>$coupon['id'],
					'remark'=>'订单满额送券活动',
				);
				$this->model('coupon')->give_coupon($params);
		}
		//游戏营销，购物参与
		foreach($this->order['goods'] as $item){
			$gamepost=array(
				'goodsid'=>$item['goodsid'],
				'type'=>2,
			);
			$this->model('game')->up_addgame($gamepost,$this->order['mid']);
		}
		$gamepost=array(
				'type'=>1,
				'price'=>$this->order['price'],
		);
		$this->model('game')->up_addgame($gamepost,$this->order['mid']);
		//多退少补
		if($this->order['addprice']<0){
			$credit=0-$this->order['addprice'];
			model('core/member')->add_credit2($this->order['mid'],$credit,'多退少补余额');
		}
		$event=array(
			'type'=>'complete',
			'order'=>$this->order,
		);
		$this->model('store')->complete_commission($this->order);
		$this->publish('order.change',$event);
	}
	public function buy_credit($order_id=0,$ismerch=false){
		if($order_id && !$this->order['id']){
			$this->get_order($order_id);
		}
		if($ismerch){
			$merchset=plugin('jy_merch')->plugin_setting('buy_credit3');
			//交由商户处理
			if($merchset['open']){
				return 0;
			}
		}
		$buy_credit=$this->plugin_setting('buy_credit');
		//根据订单金额赠送积分
		if(!$buy_credit['open'] || !$buy_credit['options']){
			return 0;
		}
		foreach($buy_credit['options'] as $item){
				if($this->order['price']>=$item['start'] && $this->order['price']<=$item['end']){
					$credit=intval($this->order['price']*$item['credit']);
					break;
				}
		}
		if($credit>0){
			if($ismerch && $this->order['merchid']){
				//是否扣部分币给商户
				$merchset=plugin('jy_merch')->plugin_setting('setting');
				if($merchset['is_koucredit']){
					$merchinfo=pdo_get('jy_merch_user',array('id'=>$this->order['merchid'],'uniacid'=>$_SESSION['uniacid']),array('choufee_set','mid'));
					$choufee_set=json_decode($merchinfo['choufee_set'],true);
					$koucredit_rate=$choufee_set['koucredit_rate']?:$merchset['koucredit_rate'];
					$merchmid=$merchinfo['mid'];
				}
				if($koucredit_rate && $merchmid){
					$kounum=$credit*$koucredit_rate/100;
					model('core/member')->member_credit($merchmid,'credit1',$kounum,true,'jy_weishop','购买商品商户获币','buy_credit3');
					$credit -=$kounum;
				}
			}
			model('core/member')->add_credit1($this->order['mid'],$credit,'购物送积分');
		}
		return $credit;
	}
	public function buy_credit3($order_id=0,$ismerch=false){
		if($order_id && !$this->order['id']){
			$this->get_order($order_id);
		}
		$buy_credit=$this->plugin_setting('buy_credit3');
		if($ismerch){
			$merchset=plugin('jy_merch')->plugin_setting('buy_credit3');
			//交由商户处理
			if($merchset['open']){
				$merchset['ismerch']=1;
				$buy_credit=$merchset;
			}
		}
		if($this->order['paytype']=='wechat' && strpos($buy_credit['paytypes'],';1;') === false){
			return 0;
		}
		if($this->order['paytype']=='credit' && strpos($buy_credit['paytypes'],';2;') === false){
			return 0;
		}
		if($this->order['paytype']=='alipay' && strpos($buy_credit['paytypes'],';3;') === false){
			return 0;
		}
		//根据订单金额赠送积分
		if(!$buy_credit['open']){
			return 0;
		}
		$credit=array();
		if($buy_credit['options']){
			foreach($buy_credit['options'] as $item){
				if($this->order['price']>=$item['start'] && $this->order['price']<=$item['end']){
					$credit[$item['type']]=intval($this->order['price']*$item['credit']);
				}
			}
		}
		foreach($this->order['goods'] as $goods){
				$goods_credit=pdo_get('jy_weishop_goods_credit',array('uniacid'=>$_SESSION['uniacid'],'goods_id'=>$goods['goodsid']));
				if(!$goods_credit['sendtype']){
					if(substr($goods_credit['credit'],-1)=='%'){
						$goods_credit['credit']=($goods['price']*$goods['total']*substr($goods_credit['credit'],0,-1))/100;
					}
					//剔除积分
					if($goods_credit['credit'] && ($goods_credit['type']>=1 || $buy_credit['ismerch'])){
						$credit[$goods_credit['type']]=$credit[$goods_credit['type']]?:0;
						$credit[$goods_credit['type']] +=intval($goods_credit['credit'])*$goods['total'];
					}
				}else{
					$goods_credit['credit_set']=json_decode($goods_credit['credit_set'],true);
					if($goods_credit['is_jieti']){
						paixu($goods_credit['credit_set'],'mannum','asc');
						foreach($goods_credit['credit_set'] as $v){
								$isnum=pdo_getsum('core_credit_log',array('mid'=>$this->order['mid'],'is_add'=>1,'type'=>$v['type'],'plugin'=>'jy_weishop','tag'=>'buy_credit3'),'fee');
								if($isnum>=$v['mannum'] || !$v['mannum']){
									$credit[$v['type']]=$v['num']*$goods['total'];
								}
						}
					}else{
						foreach($goods_credit['credit_set'] as $v){
							$credit[$v['type']]=$credit[$v['type']]?:0;
							$credit[$v['type']] +=$v['num']*$goods['total'];
						}
					}
				}
		}
		if($ismerch && $this->order['merchid']){
			//是否扣部分币给商户
			$merchset=plugin('jy_merch')->plugin_setting('setting');
			if($merchset['is_koucredit']){
					$merchinfo=pdo_get('jy_merch_user',array('id'=>$this->order['merchid'],'uniacid'=>$_SESSION['uniacid']),array('choufee_set','mid'));
					$choufee_set=json_decode($merchinfo['choufee_set'],true);
					$koucredit_rate=$choufee_set['koucredit_rate']?:$merchset['koucredit_rate'];
					$merchmid=$merchinfo['mid'];
			}
		}
		foreach($credit as $type=>$num){
			if($num<=0){
				continue;
			}
			if($koucredit_rate && $merchmid){
				$kounum=$num*$koucredit_rate/100;
				model('core/member')->member_credit($merchmid,'credit'.$type,$kounum,true,'jy_weishop','购买商品商户获币','buy_credit3');
				$num -=$kounum;
			}
			model('core/member')->member_credit($this->order['mid'],'credit'.$type,$num,true,'jy_weishop','购物送币','buy_credit3');
		}
		return $credit;
	}
	public function fang_credit2($order_id=0){
		if($order_id && !$this->order['id']){
			$this->get_order($order_id);
		}
		foreach($this->order['goods'] as $goods){
			if(!$goods['fang_credit2']){
				continue;
			}
			if(substr($goods['fang_credit2'],-1)=='%'){
				$fang_credit2=($goods['price']*$goods['total']*substr($goods['fang_credit2'],0,-1))/100;
			}else{
				$fang_credit2=$goods['total']*$goods['fang_credit2'];
			}
			if($fang_credit2){
				model('core/member')->member_credit($this->order['mid'],'credit2',$fang_credit2,true,'jy_weishop','购物返现');
			}
		}
		return true;
	}
	public function fang_credit($order_id=0){
		if($order_id && !$this->order['id']){
			$this->get_order($order_id);
		}
		foreach($this->order['goods'] as $goods){
			$goods['commissions']=$goods['commissions']?json_decode($goods['commissions'],true):'';
			if(!$goods['commissions']){
				continue;
			}
			if($goods['commissions']['credit3_fan']>0){
				model('core/member')->member_credit($this->order['mid'],'credit3',$goods['commissions']['credit3_fan'],true,'jy_weishop','购物奖励');
			}
			if($goods['commissions']['credit4_fan']>0){
				model('core/member')->member_credit($this->order['mid'],'credit4',$goods['commissions']['credit4_fan'],true,'jy_weishop','购物奖励');
			}
			if($goods['commissions']['credit5_fan']>0){
				model('core/member')->member_credit($this->order['mid'],'credit5',$goods['commissions']['credit5_fan'],true,'jy_weishop','购物奖励');
			}
			if($goods['commissions']['credit6_fan']>0){
				model('core/member')->member_credit($this->order['mid'],'credit6',$goods['commissions']['credit6_fan'],true,'jy_weishop','购物奖励');
			}
		}
		return true;
	}
	public function deduct_credit($order_id=0){
		if($order_id && !$this->order['id']){
			$this->get_order($order_id);
		}
		$saleset=$this->plugin_setting('saleset');
		if(!$saleset['deduct_credit1']){
			return false;
		}
		$delcredit1=$this->order['delcredit1'];
		if($delcredit1>0){
			model('core/member')->cut_credit1($this->order['mid'],$delcredit1,'购物抵扣积分');
		}
		return true;
	}
	public function upprice($order_id=0,$price=0,$orderprice=0,$dispatchprice=0){
		if($order_id){
			$this->get_order($order_id);
		}
		$update=array('price'=>$price);
		if($orderprice){
			$price=$orderprice+$dispatchprice;
			$update=array(
				'price'=>$price,
				'dispatchprice'=>$dispatchprice,
			);
		}
		pdo_update('jy_weishop_order',$update,array('id'=>$order_id));
		$pay_id=pdo_getcolumn('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order_id),'pay_id');
		$params=array(
			'fee'=>$price,
			'pay_id'=>$pay_id,
		);
		cfc('pay')->change_pay_fee($params);
		$this->model('notice')->notice_upprice($this->order);
		return true;
	}
	public function up_virtualtotal($tempid){
		$count=pdo_count('jy_weishop_virtual_data',array('uniacid'=>$_SESSION['uniacid'],'tempid'=>$tempid,'mid'=>0),'id');
		pdo_update('jy_weishop_goods',array('total'=>$count),array('uniacid'=>$_SESSION['uniacid'],'virtual_template_id'=>$tempid));
	}
	public function sendsubmsg($order_id){
		$this->get_order($order_id);
		$this->model('notice')->notice_pay2buyer($this->order);
		return true;
	}
	public function setfee_desc($order_id,$nomerch=false){
		$order=pdo_get('jy_weishop_order',array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		$goods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		if(!$goods){
			return false;
		}
		$allnum=count($goods);
		$merch_num=pdo_count('jy_weishop_order_goods',array('orderid'=>$order_id,'merchid >'=>0,'uniacid'=>$_SESSION['uniacid']),'id');
		if(!$merch_num && !$nomerch){
			return false;
		}
		//同一商户
		$onemerch_num=pdo_count('jy_weishop_order_goods',array('orderid'=>$order_id,'merchid'=>$order['merchid'],'uniacid'=>$_SESSION['uniacid']),'id');
		if(($onemerch_num && $onemerch_num==$merch_num) || $allnum==1){
			foreach($goods as &$ov){
				if($goodstype){
					$dispatchprice=0;
				}else{
					$dispatchprice=$order['dispatchprice'];
				}
				$goodsprice=$ov['price']*$ov['total'];
				if($allnum==1){
					$total_price=$order['price'];
				}else{
					$total_price=$goodsprice*$order['price']/$order['goodsprice'];
				}
				$fee_desc=array(
					'dispatchprice'=>$dispatchprice,
					'level_de_price'=>$order['level_de_price'],
					'luck_de_price'=>$order['luck_de_price'],
					'enough_de_price'=>$order['enough_de_price'],
					'coupon_de_price'=>$order['coupon_de_price'],
					'deductcredit'=>$order['deductcredit'],
					'deductcredit2'=>$order['deductcredit2'],
				);
				pdo_update('jy_weishop_order_goods',array('fee_desc'=>ijson_encode($fee_desc),'total_price'=>$total_price),array('id'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']));
			}
			return false;
		}
		foreach($goods as &$item){
			if(!$item['merchid'] && !$nomerch){
				continue ;
			}
			$goodsprice=$item['price']*$item['total'];
			$feerate=$goodsprice/$order['goodsprice'];
			$syscoupon=pdo_getcolumn('jy_weishop_coupon',array('id'=>$order['couponid']),'merchid');
			//如果是商户自己的优惠券，就由商户支出
			if($syscoupon==$item['merchid']){
				$merchcoupon_num=pdo_count('jy_weishop_order_goods',array('orderid'=>$order_id,'merchid'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid']),'id');
				if($merchcoupon_num){
					$coupon_de_price=$order['coupon_de_price']/$merchcoupon_num;
				}
			}else if($syscoupon){
				$coupon_de_price=0;
			}else{
				$coupon_de_price=$order['coupon_de_price']*$feerate;
			}
			//计算各种商户的运费
			$goodstype=pdo_getcolumn('jy_weishop_goods',array('id'=>$item['goodsid']),'type');
			if($goodstype){
				$dispatchprice=0;
			}else{
				$dispatchprice=$order['dispatchprice']*$feerate;
			}
			$fee_desc=array(
				'dispatchprice'=>$dispatchprice,
				'level_de_price'=>$order['level_de_price']*$feerate,
				'luck_de_price'=>$order['luck_de_price']*$feerate,
				'enough_de_price'=>$order['enough_de_price']*$feerate,
				'coupon_de_price'=>$coupon_de_price,
				'deductcredit'=>$order['deductcredit']*$feerate,
				'deductcredit2'=>$order['deductcredit2']*$feerate,
			);
			$total_price=$goodsprice+$dispatchprice-$fee_desc['level_de_price']-$fee_desc['luck_de_price']-$fee_desc['enough_de_price']-$fee_desc['coupon_de_price']-$fee_desc['deductcredit']-$fee_desc['deductcredit2'];
			pdo_update('jy_weishop_order_goods',array('fee_desc'=>ijson_encode($fee_desc),'total_price'=>$total_price),array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
		}
		return $fee_desc;
	}
	public function send_orderverify($order_id){
		$this->get_order($order_id);
		/*
			按商品虚拟商品和核销商品自动发货
			非拼团订单，才自动发货
		*/
		if($this->order['is_team']!=1){
			foreach($this->order['goods'] as $vv){
				//已经整理出了商品类型type,isverify，只要支持核销，无论什么商品都可以核销！
				if($vv['isverify']==1 && $vv['type']!=2){
					if($vv['type']==3){
						$this->order_send_verifygoods($order_id,$vv['goodsid'],$this->order['sendtype']);
					}elseif($vv['type']==0){
						//实体物品，需配送时，依然生成核销码，但是不刷新配送状态
						$this->order_send_verify($order_id,$vv['goodsid'],$this->order['sendtype']);
					}else{
						$this->order_send_verify($order_id,$vv['goodsid'],$this->order['sendtype']);
					}
				}elseif($vv['type']==1 || $vv['type']==2){
					//虚拟发货，如果是自动发货
					$goods=pdo_get('jy_weishop_goods',array('id'=>$vv['goodsid']),array('type','virtualsend','virtualsendcont','virtual_template_id'));
					if(($goods['virtualsend']) || $vv['type']==2){
						$vv=array_merge($vv,$goods);
						$this->order_send_virtual($order_id,$vv);
					}
				}
			}
		}
		return true;
	}
	public function add_baobei($order_id,$msg='',$oldstatus=2,$mid=0,$api_id=0,$api_pluginname=''){
		$mid=$mid?:$_SESSION['uid'];
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'order_id'=>$order_id,
			'oldstatus'=>$oldstatus?:2,
			'api_id'=>$api_id,
			'api_pluginname'=>$api_pluginname,
			'mid'=>$mid,
			'msg'=>$msg?:'异常报备',
			'status'=>0,
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_weishop_baobei_log',$data);
		$logid=pdo_insertid();
		pdo_update('jy_weishop_order',array('status'=>7),array('id'=>$order_id));
		return $logid;
	}
	//自定义交易组件传参
	public function getwx_shoppayment($order_id,$tid='',$scene=''){
		$jy_wxappjiaoyi = $this->plugin_exists('jy_wxappjiaoyi');
		if(!$jy_wxappjiaoyi){
			return false;
		}
		$jy_wxappjiaoyi=plugin('jy_wxappjiaoyi')->plugin_setting('basic');
		if(!$jy_wxappjiaoyi['iswxshop'] && !in_array($scene,array(1175,1176,1177,1184,1184,1191,1193,1195,1197,1198,1201,1206,1216))){
			return false;
		}
		$order_info=$this->getorder_infodate($order_id,$tid);
		if($order_info){
			$apiorder_id=model('jy_wxappjiaoyi/wxapp_api')->order_add($order_id,$tid);
			if($apiorder_id){
				$paymentparams=model('jy_wxappjiaoyi/wxapp_api')->getpaymentparams($order_id,$apiorder_id,$tid);
				$paymentparams['order_info']=$order_info;
				pdo_update('jy_weishop_order',array('api_data'=>ijson_encode(array('iswxshop'=>1))),array('id'=>$order_id));
			}
		}
		return $paymentparams;
	}
	public function getorder_infodate($order_id,$tid=''){
		$order=$this->get_order($order_id);
		if(!$order['id']){
			return false;
		}
		if(!$_SESSION['openid']){
			$fans=cfc('fans')->get_fansinfo($order['mid'],1);
			$openid=$fans['openid'];
		}
		$goods=array();
		$goodsprice=0;
		foreach($order['goods'] as $item){
			$goods[]=array(
				'out_product_id'=>$item['goodsid'],
				'out_sku_id'=>$item['optionid'],
				'product_cnt'=>$item['total'],
				'sale_price'=>$item['price']*100,
				'real_price'=>$item['price']*100,
				'sku_real_price'=>$item['price']*$item['total']*100,
				'path'=>'jy_weishop_en/goods/detail/index?id='.$item['goodsid'],
				'title'=>$item['title'],
				'head_img'=>tomedia($item['image']),
			);
			$goodsprice +=$item['price']*$item['total']*100;
		}
		$freight=$order['dispatchprice']*100;
		if($order['price']*100>$goodsprice+$freight){
			$freight=$order['price']*100-$goodsprice;
			$discounted_price=0;
		}else{
			$discounted_price=$goodsprice+$freight-$order['price']*100;
		}
		$order_detail=array(
			'product_infos'=>$goods,
			'pay_info'=>array(
				'pay_method_type'=>0,
				'prepay_id'=>$order['pay_id'],
				'prepay_time'=>date('Y-m-d H:i:s',time()),
			),
			'price_info'=>array(
				'order_price'=>$order['price']*100,
				'freight'=>$freight,
				'discounted_price'=>$discounted_price?:0,
				'additional_price'=>0,
				'additional_remarks'=>'税费',
			),
		);
		//delivery_type:视频号场景目前只支持 1，正常快递
		$order_info=array(
				'create_time'=>date('Y-m-d H:i:s',$order['createtime']),
				'out_order_id'=>$tid?:$order_id,
				'openid'=>$openid?:$_SESSION['openid'],
				'path'=>'jy_weishop_en/order/detail/index?id='.$order_id,
				'out_user_id'=>$order['mid'],
				'order_detail'=>$order_detail,
				'delivery_detail'=>array('delivery_type'=>1),
				'fund_type'=>1,
		);
		//用户地址
		$order['address']=json_decode($order['address'],true);
		if($order['address'] && $order['address']['name']){
			$address=$order['address'];
		}else{
			$address=pdo_get('core_address',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['addressid']));
		}
		$address['pcd']=json_decode($address['pcd'],true);
		$address_info=array(
					'receiver_name'=>$address['name'],
					'detailed_address'=>$address['address'],
					'tel_number'=>$address['mobile'],
					'country'=>'中国',
					'province'=>$address['pcd']['province'],
					'city'=>$address['pcd']['city'],
					'town'=>$address['pcd']['town'],
		);
		if($order['sendtype']==1){
			$order_info['address_info']=$address_info;
		}
		return $order_info;
	}
}